asm
  ld sp,$F7FF
  end asm


#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"

dim eee as uinteger at $F010
dim seed as uinteger at $F012
dim ee0 as uinteger at $F014
dim ee1 as uinteger at $F016
dim ee2 as uinteger at $F018
dim ee3 as uinteger at $F01A
dim eex as uinteger at $F01C
dim eey as uinteger at $F01E

sub tankbustersputcharfg(txp1 as uinteger, typ1 as uinteger, tch1 as ubyte, tat1 as ubyte):
  poke $D000+typ1+((txp1 bxor 31)*64),(tch1 band 63)+((tat1 band 3)*64)
  end sub

sub tankbustersputcharbg(txp1 as uinteger, typ1 as uinteger, tch1 as ubyte, tat1 as ubyte):
  poke $C000+typ1+((txp1 bxor 31)*64),tch1
  poke $C800+typ1+((txp1 bxor 31)*64),tat1
  end sub

'- create a sub for offset
poke $E800,8
poke $E801,128
poke $E802,1


seed=0

for ee0=0 to 63
  for ee1=0 to 31
    tankbustersputcharfg(ee1,ee0,32,0)
    next:next

for ee0=0 to 63
  for ee1=0 to 31
    seed=smsrnd(seed)
    ee2=seed
    seed=smsrnd(seed)
    tankbustersputcharbg(ee1+0,ee0+0,seed band 7,(ee2 band 31)*8)
    next:next


for ee0=0 to 15
  for ee1=0 to 15
    tankbustersputcharbg(ee1+13,ee0+23,ee0*16+ee1,0)
    next:next


eex=8:eey=8
eee=0

do

tankbustersputcharbg(1,1,48+(int(eee/100) mod 10),0)
tankbustersputcharbg(2,1,48+(int(eee/10) mod 10),0)
tankbustersputcharbg(3,1,48+(eee mod 10),0)

ee0=peek($E800) bxor $FF
tankbustersputcharbg(1,3,48+(int(ee0/100) mod 10),0)
tankbustersputcharbg(2,3,48+(int(ee0/10) mod 10),0)
tankbustersputcharbg(3,3,48+(ee0 mod 10),0)

eey=eey-((ee0 band 1)/1)+((ee0 band 2)/2)
eex=eex+((ee0 band 4)/4)-((ee0 band 8)/8)

ee0=peek($E801) bxor $FF
tankbustersputcharbg(1,4,48+(int(ee0/100) mod 10),0)
tankbustersputcharbg(2,4,48+(int(ee0/10) mod 10),0)
tankbustersputcharbg(3,4,48+(ee0 mod 10),0)

tankbustersputcharbg(eex,eey,eee mod 128,0)

seed=smsrnd(seed)
poke $D800+(eee band $FF),seed

eee=eee+1

pacmandelay(1000)

loop

do:loop









do

poke $E800,eee '+x
poke $E801,128 '-y
poke $E802,1



pacmandelay(10000)
eee=eee+1
loop



do:loop





for eee=$D000 to $D7FF '- txtram?
  seed=smsrnd(seed)
  poke eee,eee
  pacmandelay(10000)
  next

do:loop


do
for eee=$D000 to $D7FF '- txtram?
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(10000)
  next
loop

do

for eee=$C000 to $C7FF '- videoram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  next

for eee=$C800 to $CFFF '- colorram
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  next

for eee=$D000 to $D7FF '- txtram?
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  next

for eee=$D800 to $D8FF '- spriteram?
  seed=smsrnd(seed)
  poke eee,seed
  pacmandelay(1000)
  next

loop



do:loop




'- static ADDRESS_MAP_START( main_map, AS_PROGRAM, 8, tankbust_state )
'- AM_RANGE(0x0000, 0x5fff) AM_ROM
'- AM_RANGE(0x6000, 0x9fff) AM_ROMBANK("bank1")
'- AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank2")
'- AM_RANGE(0xc000, 0xc7ff) AM_RAM_WRITE(background_videoram_w) AM_SHARE("videoram")
'- AM_RANGE(0xc800, 0xcfff) AM_RAM_WRITE(background_colorram_w) AM_SHARE("colorram")
'- AM_RANGE(0xd000, 0xd7ff) AM_RAM_WRITE(txtram_w) AM_SHARE("txtram")
'- AM_RANGE(0xd800, 0xd8ff) AM_RAM AM_SHARE("spriteram")
'- AM_RANGE(0xe000, 0xe007) AM_READWRITE(debug_output_area_r, e0xx_w)
'- AM_RANGE(0xe800, 0xe800) AM_READ_PORT("INPUTS") AM_WRITE(yscroll_w)
'- AM_RANGE(0xe801, 0xe801) AM_READ_PORT("SYSTEM")
'- AM_RANGE(0xe802, 0xe802) AM_READ_PORT("DSW")
'- AM_RANGE(0xe801, 0xe802) AM_WRITE(xscroll_w)
'- AM_RANGE(0xe803, 0xe803) AM_READWRITE(some_changing_input, soundlatch_w)   /*unknown. Game expects this to change so this is not player input */
'- AM_RANGE(0xe804, 0xe804) AM_WRITENOP    /* watchdog ? ; written in long-lasting loops */
'- AM_RANGE(0xf000, 0xf7ff) AM_RAM
'- //AM_RANGE(0xf800, 0xffff) AM_READ(read_from_unmapped_memory)   /* a bug in game code ? */
'- ADDRESS_MAP_END














